package com.wc.AlgoOJ_homework.AlgoOJ_test5.A_打靶练习;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/18 19:00
 * @description http://43.138.190.70:8888/p/991?tid=65f4f2f02337f3a932b4945c
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int t;
    static char[][] cs = new char[15][15];

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            for (int i = 1; i <= 10; i++) {
                cs[i] = (" " + sc.next()).toCharArray();
            }
            int res = 0;
            for (int i = 1; i <= 10; i++) {
                for (int j = 1; j <= 10; j++) {
                    if (cs[i][j] == 'X') {
                        if (i == 1 || j == 1 || i == 10 || j == 10) {
                            res += 1;
                        } else if (i == 2 || i == 9 || j == 2 || j == 9) {
                            res += 2;
                        } else if (i == 3 || i == 8 || j == 3 || j == 8) {
                            res += 3;
                        } else if (i == 4 || i == 7 || j == 4 || j == 7) {
                            res += 4;
                        } else {
                            res += 5;
                        }
                    }
                }
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
